package utils

import (
	"authserver/global"
	"github.com/go-auxiliaries/selenium"
	"net"
)

func StartServer() (err error) {

	opts := []selenium.ServiceOption{
		selenium.Output(nil),
	}
	selenium.SetDebug(false)
	global.ChromePort = 6688
	global.ChromeService, err = selenium.NewChromeDriverService("Chrome\\chromedriver.exe", 6688, opts...)
	if err != nil {
		panic(err)
	}
	return
}


func pickUnusedPort() (int, error) {
	addr, err := net.ResolveTCPAddr("tcp", "127.0.0.1:0")
	if err != nil {
		return 0, err
	}

	l, err := net.ListenTCP("tcp", addr)
	if err != nil {
		return 0, err
	}
	port := l.Addr().(*net.TCPAddr).Port
	if err := l.Close(); err != nil {
		return 0, err
	}
	return port, nil
}
